// 导入request.js请求工具
import request from '@/utils/request.js'

// 提供调用注册接口的函数
export const userRegisterService = (registerData) => {
    // 处理参数registerData为接口要求的x-www-form-urlencoded格式
    // 借助urlSearchParams对象
    const urlSearchParams = new URLSearchParams();
    for (let key in registerData) {
        urlSearchParams.append(key, registerData[key]);
    }
    return request.post('/user/register', urlSearchParams);
}

// 提供调用登录接口的函数
export const userLoginService = (loginData) => {
    // 处理参数loginData为接口要求的x-www-form-urlencoded格式
    // 借助urlSearchParams对象
    const urlSearchParams = new URLSearchParams();
    for (let key in loginData) {
        urlSearchParams.append(key, loginData[key]);
    }
    return request.post('/user/login', urlSearchParams);
}

// 获取用户详细信息
export const userInfoService = () => {
    return request.get('/user/userInfo');
}

// 修改个人信息
export const updateUserInfoService = (userInfoData) => {
    return request.put('/user/update', userInfoData);
}

// 更新头像
export const updateAvatarService = (avatarUrl) => {
    const urlSearchParams = new URLSearchParams();
    urlSearchParams.append('avatarUrl', avatarUrl);
    return request.patch('/user/updateAvatar',urlSearchParams);
}

// 修改密码
export const updatePasswordService = (passwordData) => {
    return request.patch('/user/updatePwd', passwordData);
}